<?php
?>
<script language="javascript">

	jQuery(document).ready(function(){
		jQuery('#list').jqGrid({
			url: '<?=site_url() ?>/gonapi/getData/',
			mtype: 'POST',
            datatype: 'json',
            colNames:['ID','Referencia', 'Tipo','C. Servicio','Registro','Fecha R.','D.U.','Etapa A.','Estatus','Etapa',
                      'Total','User','Responsable'],
                     colModel :[
                          {name:'IdCompania', index:'IdCompania', width:5,hidden:true},
                          {name:'NombreCompania', index:'NombreCompania', width:80},
                          {name:'IdServicio', index:'IdServicio', width:40},
                          {name:'cServicio', index:'clasificacion_servicios', width:40},
                      	  {name:'FechaUsrCompania', index:'FechaUsrCompania', width:40},
                       	  {name:'FechaSistema', index:'FechaSistema', width:40},
                      	  {name:'dias', index:'dias', width:20},
                      	  {name:'IdEtapa',index:'idStatu',width:35},
                      	  {name:'IdEstatus',index:'idStatu',width:35},
                      	  {name:'Etapa', index:'Etapa', width:32},
                      	  {name:'Total', index:'Total', width:32},
                      	  {name:'User', index:'IdUsuario', width:35},
                      	  {name:'Responsable', index:'IdResponsable', width:40}],
            pager: jQuery('#pager'),
            hiddengrid: true,
            sortname: 'IdCompania',
            rowNum:30,       
            rowList:[30,40],
            sortorder: "ASC",
            height: '100%',
            width: '610',
            imgpath: _base_url + 'public/css/jqgrid/flex/images',
            viewrecords: true,
            multiselect: true,
            onSelectRow: function(ids) 
            {
            	if(ids != null) 
            	{
            		var rec = jQuery("#list").getRowData(ids);
            		lol=ids;
            	}
            },
            adjacents: 4,
            jsonReader: { repeatitems : false, id_Categoria: "0"}
        }).navGrid('#pager',{add:false,del:false,edit:false,search:false,position:"left"})
        .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/text_columns.png", onClickButton:function(){ jQuery("#list").setColumns();}})
        <?php if ($this->session->userdata('LOGGED_DEPAR') == 4 || $this->session->userdata('LOGGED_DEPAR') == 1): ?>
     
       .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/img/icons/page_white_delete.png", onClickButton:function(){
           var id = jQuery('#list').getGridParam('selarrrow');
           var id=lol;
             if (id.length > 0){  
         	     var ret = jQuery("#list").getRowData(id);
                   window.location = _site_url + '/main_tran/hsegui/' + ret.IdCompania;
         
     } else { jAlert('Debe seleccionar al menos una compania'); }
     return false; } })
     <?php endif;?>

      
      .navButtonAdd('#pager',{caption:"Agregar", buttonimg: _base_url + "public/images/new.png", onClickButton:
       function(){ window.location = _site_url + "/trancrearcompania/addCompania";}})
  
       .navButtonAdd('#pager',{
    	   caption:"Detalles", 
     	  buttonimg: _base_url + "public/images/new.png", 
   	   onClickButton: function(){ 
   		   var idFila = jQuery('#list').getGridParam('selarrrow');
   		   if(idFila.length == 1){
   			   filaSeleccionada = $("#list").getRowData(idFila);
                 	window.location = '<?php echo site_url()?>/indicadoresseguimientoci/companyDetails/'+filaSeleccionada['IdCompania'];
       	   }else if(idFila.length >= 2){
       		   jAlert("Solo puedes seleccionar un registro a la vez\npara mostrar los detalles");
              }else{
				jAlert("Debe seleccionar un registro");
              }   
   	   }
   	 })
   	
    .navButtonAdd('#pager',{caption:"Send Mail.", buttonimg: _base_url + "public/img/icons/mail-ico.png", onClickButton:function(){ 
     var id = jQuery('#list').getGridParam('selarrrow');
   	if (id.length > 0) {
       	 
   		 var s; 
       	 s = jQuery("#list").getGridParam('selarrrow'); 
       	 var ret = jQuery("#list").getRowData(s[2]);
       	 var miArray = ''; 
            var companiaMsg = '';
            
       	 for(var i = 0;i < id.length; i++)
       	 {
       	 	if(miArray.length > 0)
       	 	{
       	 	   miArray= miArray+'-'+jQuery("#list").getRowData(s[i]).IdCompania;
       	 	}
       	 	else
       	 	{
       	 	   miArray=jQuery("#list").getRowData(s[i]).IdCompania;
       	 	}
             var  index = i + 1;
       	 	companiaMsg = companiaMsg+index+'.'+jQuery("#list").getRowData(s[i]).NombreCompania+'<br/>';
       	 }

     	      msg = '<font style="color:#1C1C1C;font-weight:600;font-size: 14px">Enviar Mail a </font> <br/> <font style="color: #0404B4;font-weight:500;font-size: 10px">'+companiaMsg+'</font>';
              jConfirm(msg, 'Dialogo de Confirmacion', function (r) {
              if(r) {
              	 id=jQuery('#list').getGridParam('selrow');
                ret = jQuery("#list").getRowData(id);
                window.location = _site_url + '/setupseguimiento/sendmail/'+miArray;
                }
             });
        }else { jAlert('Debe seleccionar un registro'); }
                 return false; } })});
	 var flAuto = true;
	 var timeoutHnd; 

	 function doSearch(ev)
	 { 
	       if(!flAuto) return; 
	       // var elem = ev.target||ev.srcElement; 
	       if(timeoutHnd) 
	           clearTimeout(timeoutHnd); 
	           timeoutHnd = setTimeout(gridReload,500); 
	 }
	  
	 function enableAutosubmit(state)
	 { 
	       flAuto = state; 
	       jQuery("#submitButton").attr("disabled",state); 
	 }
	 
	 function gridReload()
	 { 
		     
	          var et_mask = jQuery("#search_et").val();
	         
	          var color_mask = jQuery("#search_color").val();
	          var array_search = color_mask+'-'+et_mask;
	          jQuery("#list").setGridParam({url :'<?=site_url() ?>/gonapi/getData/0/'+array_search, page : 1}).trigger('reloadGrid'); 
	 }
</script>

<div class="table_container">
	<a href="<?php echo site_url();?>/indicadoresgonapi"><font size = "3%" >Indicadores G-ONAPI</font></a>
	<font size = "3%" >|</font>
	<b style="background-color: green;"><font size = "2%" color="white">Indicador Actual = <?=$porcentajeEstatus['verdes']?>%</font></b>
	<font size = "3%" >|</font>
	<b style="background-color: yellow;"><font size = "2%" color="black">Observaci&oacute;n Amarillos = <?=$porcentajeEstatus['amarillos']?>%</font></b>
	<table>
		<tr>
			<td><div id="titulo">Listado de Campa&ntilde;ias en clasificaci&oacute;n ONAPI</div></td>
		</tr>
		<tr>
			<td style="background: #D9E6F0;border: 1px solid #C3AA64; height: 23px">
			&nbsp;&nbsp;&nbsp;&nbsp;<b>Color:<b/> <select id='search_color' onChange='doSearch(arguments[0]||event)' ><option></option> <?php foreach ($colores as $k): echo '<option value="'.$k.'">'.$k.'</option>'; endforeach;?></select>
             &nbsp;&nbsp;&nbsp;&nbsp;<b>Etapa:<b/> <select id='search_et' onChange='doSearch(arguments[0]||event)' ><option></option> <?php foreach ($etapas as $k): echo '<option value="'.$k->GetIdEtapa().'">'.$k->GetNombre().'</option>'; endforeach;?></select>
			</td>
		</tr>
		<tr>
			<td>
				<table id="list" class="scroll"></table>
				<div id="pager" class = "scroll" style="text-aling:center;"></div>
			</td>
		</tr>
	</table><br/>
	<?php $this->load->view('gventas24h_view')?>
</div>